﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Utility
{
    /// <summary>
    /// 页面传送参数处理
    /// </summary>
    public static class ParamsOfRequest
    {
        /// <summary>
        /// 页面get方式传送参数
        /// </summary>
        /// <param name="sParam">参数名称</param>
        /// <returns>如果为空返回string.Empty空串，其他返回Trim之后的字符串</returns>
        public static string Request(string sParam)
        {
            return (HttpContext.Current.Request.Params[sParam] == null ? string.Empty : HttpContext.Current.Request.Params[sParam].ToSafeString().ToUrlDecode());
        }
        /// <summary>
        /// 页面post方式传送参数
        /// </summary>
        /// <param name="name">参数名称</param>
        /// <returns>如果为空返回string.Empty空串，其他返回Trim之后的字符串</returns>
        public static string RequstForm(string sParam)
        {
            return (HttpContext.Current.Request.Params[sParam] == null ? string.Empty : HttpContext.Current.Request.Params[sParam].ToSafeString());
        }
        /// <summary>
        /// 页面get方式传送参数
        /// </summary>
        /// <param name="sParam">参数名称</param>
        /// <returns>如果为空返回string.Empty空串，其他返回Trim之后的字符串</returns>
        public static string RequstString(string sParam)
        {
            return (HttpContext.Current.Request.Params[sParam] == null ? string.Empty : HttpContext.Current.Request.Params[sParam].ToSafeString());
        }
        /// <summary>
        /// 页面get方式传送参数，获得int型
        /// </summary>
        /// <param name="sParam">参数名称</param>
        /// <returns>返回整数类型的参数</returns>
        public static int RequstStringByInt(string sParam)
        {
            return RequstForm(sParam).ToSafeInt();
        }
        /// <summary>
        /// 页面get方式传送参数，获得int型
        /// </summary>
        /// <param name="sParam">参数名称</param>
        /// <returns>返回整数类型的参数</returns>
        public static int RequstInt(string sParam)
        {
            return RequstForm(sParam).ToSafeInt();
        }
        /// <summary>
        /// easyui特用的属性（排序参数asc或者desc）
        /// </summary>
        public static string order
        {
            get { return RequstForm("order"); }
        }
        /// <summary>
        /// easyui特用的属性（是否排序）
        /// </summary>
        public static string sort
        {
            get { return RequstForm("sort"); }
        }
        /// <summary>
        /// easyui特用的属性（分页）
        /// </summary>
        public static int page
        {
            get { return RequstInt("page"); }
        }
        /// <summary>
        /// easyui特用的属性（行数）
        /// </summary>
        public static int rows
        {
            get { return RequstInt("rows"); }
        }



        /// <summary>
        /// jqGrid 显示行数
        /// </summary>
        public static int jqGridRows
        {
            get { return RequstInt("rows"); }
        }
        /// <summary>
        /// jqGrid当前页
        /// </summary>
        public static int jqGridPageIndex
        {
            get { return RequstInt("page"); }
        }
        /// <summary>
        /// jqGrid排序字段 
        /// </summary>
        public static string jqGridSortField
        {
            get { return RequstString("sidx"); }
        }
        /// <summary>
        /// jqGrid排序(desc/asc)
        /// </summary>
        public static string jqGridSortBy
        {
            get { return RequstString("sord"); }
        }
    }
}
